import { loginAPI } from '@/api/user'
import { setToken, getToken, removeToken } from '@/utils/auth'
// import { setToken } from '@/utils/auth'
export default {
  namespaced: true,
  state: {
    token: getToken() || ''
  },
  mutations: {
    setToken(state, newToken) {
      state.token = newToken
      setToken(newToken)
    },
    removeToken(state) {
      // 清空vuex中的token
      state.token = ''
      // 清空cookie中的token
      removeToken()
    }
  },
  actions: {
    async loginAction(store, data) {
      const res = await loginAPI(data)
      // console.log(res)
      store.commit('setToken', res.data.token)
    }
  },
  getters: {}
}
